home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / caratulasdecine + Google (ES).ifs < prev    next >
Encoding:
Text File  |  2004-03-24  |  4.8 KB  |  159 lines

  1. // GETINFO SCRIPTING
  2. // CaratulasDeCine+Google v1.0 by japg2000 & micmic
  3.  
  4. (***************************************************
  5.  *  Author: japg2000 (japg2000@terra.es)           *
  6.  *          micmic   (micmic@dieznet.com)          *
  7.  *  Script for the importation of pictures from    *
  8.  *  caratulasdecine                                *
  9.  *                                                 *
  10.  *  For use with Ant Movie Catalog 3.4.0           *
  11.  *  www.ant.be.tf/moviecatalog ╖╖╖ www.buypin.com  *
  12.  *                                                 *
  13.  *  The source code of the script can be used in   *
  14.  *  another program only if full credits to        *
  15.  *  script author and a link to Ant Movie Catalog  *
  16.  *  website are given in the About box or in       *
  17.  *  the documentation of the program               *
  18.  ***************************************************)
  19.  
  20.  
  21. program CaratulasdecineImport;
  22. var
  23.   MovieName: string;
  24. const
  25.   Dominio = 'www.caratulasdecine.com';
  26.   BaseURL1 = 'http://www.google.com/custom?hl=es&ie=ISO-8859-1&cof=&domains=';
  27.   BaseURL2 = '&q=';
  28.   BaseURL3 = '&btnG=B%FAsqueda+en+Google&sitesearch=';
  29.  
  30. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  31. var
  32.   i: Integer;
  33. begin
  34.   result := -1;
  35.   if StartAt < 0 then
  36.     StartAt := 0;
  37.   for i := StartAt to List.Count-1 do
  38.     if Pos(Pattern, List.GetString(i)) <> 0 then
  39.     begin
  40.       result := i;
  41.       Break;
  42.     end;
  43. end;
  44.  
  45. function EliminaInicio(S: string; CR: string): string;
  46. begin
  47.   result := S;
  48.   while Pos(CR, result) = 1 do
  49.   begin
  50.     Delete(result, 1, Length(CR));
  51.   end;
  52. end;
  53.  
  54. function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
  55. var
  56.   InicioPos: Integer;
  57. begin
  58.   InicioPos := Pos(StartTag, S);
  59.   Delete(S, 1, InicioPos + Length(StartTag) - 1);
  60.   InicioPos := Pos(EndTag, S);
  61.   result := copy(S, 1, InicioPos - 1);
  62.   Delete(S, 1, InicioPos + 1);
  63. end;
  64.  
  65. procedure AnalyzePage(Address: string);
  66. var
  67.   Page: TStringList;
  68.   LineNr: Integer;
  69.   PosIni, PosFin: Integer;
  70.   Line, SubLine: string;
  71.   Title, DirURL: string;
  72.   txtTemp: string;
  73. begin
  74.   Page := TStringList.Create;
  75.   Page.Text := GetPage(Address);
  76.   if Pos('No se encontr≤ ninguna pßgina', Page.Text) > 0 then
  77.   begin
  78.     ShowMessage('No se ha encontrado ning·n artφculo por tφtulo.');
  79.   end else
  80.   begin
  81.     PickTreeClear;
  82.     PickTreeAdd('Resultados de la b·squeda para "' + MovieName + '" (' + Dominio + ') por Google:', '');
  83.    
  84.     Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  85.     Page.Text := StringReplace(Page.Text, '<p class=g>', #13#10 + '<p class=g>');
  86.  
  87.     // buscamos los resultados
  88.     LineNr := 0;
  89.  
  90.     while LineNr < Page.Count do
  91.     begin
  92.       SubLine := Page.GetString(LineNr);
  93.       txtTemp := '<p class=g><a href=';
  94.       PosIni := pos(txtTemp, SubLine);
  95.       if PosIni > 0 then
  96.       begin
  97.         SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
  98.         txtTemp := '>';
  99.         PosFin := pos(txtTemp, SubLine);
  100.         DirURL := Copy(SubLine, 1, PosFin - 1);
  101.         DirURL := StringReplace(DirURL, '"', '');
  102.        
  103.         SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
  104.         txtTemp := '</a>';
  105.         PosFin := pos(txtTemp, SubLine);
  106.         Title := Copy(SubLine, 1, PosFin - 1);
  107.         HTMLRemoveTags(Title);
  108.  
  109.         //ShowMessage(Title + '-->' + DirURL);
  110.         PickTreeAdd(Title, DirURL);
  111.       end;
  112.       LineNr := LineNr + 1;
  113.     end;
  114.  
  115.     Page.Free;
  116.     if PickTreeExec(Address) then
  117.       AnalyzeMoviePage(Address);
  118.   end;
  119. end;
  120.  
  121. procedure AnalyzeMoviePage(Address: string);
  122. var
  123.   MoviePage: TStringList;
  124.   LineNr: Integer;
  125.   Line: string;
  126. begin
  127.  
  128.   MoviePage := TStringList.Create;
  129.   MoviePage.Text := GetPage(Address);
  130.  
  131.   LineNr := FindLine('<title>', MoviePage, 0);
  132.   Line := MoviePage.GetString(LineNr);
  133.   Line := CadenaEntre(Line, '<title>', '</title>');
  134.   SetField(fieldTranslatedTitle, Line);
  135.  
  136.   LineNr := FindLine('<p align="center"><img src="', MoviePage, 0);
  137.   Line := MoviePage.GetString(LineNr);
  138.   Line := CadenaEntre(Line, '<p align="center"><img src="', '" ');
  139.   Line := EliminaInicio(Line, '../');
  140.   GetPicture('http://www.caratulasdecine.com/' + Line, True);
  141.  
  142.   MoviePage.Free;
  143.   DisplayResults;
  144. end;
  145.  
  146. // bmicmic: Bucle Principal
  147. begin
  148.   if CheckVersion(3,4,0) then
  149.   begin
  150.     MovieName := GetField(fieldOriginalTitle);
  151.     if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);
  152.  
  153.     Input('Importar de ' + Dominio + ' (por Google)', 'Introduce el Titulo de la Pelicula:', MovieName);
  154.     AnalyzePage(BaseURL1 + Dominio + BaseURL2 + UrlEncode(MovieName) + BaseURL3 + Dominio);
  155.  
  156.   end else
  157.        ShowMessage('Este script necesita una versi≤n superior de Ant Movie Catalog (al menos la version 3.4.0)');
  158. end.
  159.